package _32define;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
import java.util.stream.Collectors;

public class HomeWork1 {
    public static void main(String[] args) {
        Collection<User1> collection=new ArrayList();
        collection.add(new User1("zs",18));
        collection.add(new User1("zs",18));
        collection.add(new User1("ls",19));
        collection.add(new User1("ww",20));
        System.out.println(collection);
        Collection<User1> newArr=collection.stream().distinct().collect(Collectors.toList());
        System.out.println(newArr);
    }
}
class User1{
    private String name;
    private int age;

    public User1(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    public boolean equals(Object o){
        if (this==o){
            return true;
        }
        if (o==null||getClass()!=o.getClass()){
            return false;
        }
        User1 user=(User1) o;
        return age== user.age&& Objects.equals(name,user.name);
    }
    public int hashCode(){
        return Objects.hash(name,age);
    }

    @Override
    public String toString() {
        return "User1{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
